<template>
<div class="idsshow-wrapper" v-if="names">
  <template v-for="(info,id) in names">
      <span v-show="false">
          {{b=col.auths?col.auths.contains(info.menu_id):false}}
          {{check=col.is_admin||b}}</span>
    <span v-if="check">
      <router-link v-if="id" :to="{path:'/page/list',query:{ctl:col.ctl,id}}">{{info.name}}</router-link>
    </span>
      <span v-else>{{info.name}}</span>
      <template v-if="id!=lastId">&nbsp;|&nbsp;</template>

  </template>
</div>
</template>
<script>
import tool from 'src/util/tool';
import util from '_util/index';
import _ from 'lodash';


export default {
  data() {
    return {
      names: null,
    }
  },
  watch: {
    col: function() {
      this.setName();
    }
  },
  methods: {

    setName() {
      if(!this.col.rs) {
          this.names= null;
          return;
      }
        let ids = this.col.rs.split('|').filter(id => id);
      let ctl = this.col.ctl
      let current_names = this.$store.state.global.current_names;
      let names = {};
      if(current_names&&current_names[ctl]) {
        let [namesObj,menu_id] = current_names[ctl];
        util.forEach(ids,(ind,id) => {
            names[id]={
                name:namesObj[id]|| `ID:${id}`,
                menu_id
            };
        });

      }

      this.names= names;
    }
  },
  props: ['col'],
  computed: {
      lastId(){
          return this.names?_.last(Object.keys(this.names)):0;
      }
  },
  created() {
    this.setName();
  }
};
</script>
<style rel="stylesheet/less" lang="less">@dir: "cell/";</style>
